package com.rd.student.jike.class2.lihongming.week724_730.Day728;

import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * @Auther:Heinrich
 * @Date:2023/7/28-07-28-11:50
 * @Description:c230728
 * @version:1.0
 */
public class RandomAccessFileTest {
    //从指定位置开始读取文件的一部分，或随机读取文件
    //seek()可以定位要读写的指针位置
    //getFilePointer()获取当前指针位置


    public static void main(String[] args) throws IOException {
        RandomAccessFile file =
                new RandomAccessFile("stream.txt","rw");
        file.seek(1);
        long pointer = file.getFilePointer();
        byte[] arr = new byte[1024];
        file.read(arr,0, (int) file.length());
        long endPointer = file.getFilePointer();
        System.out.println(pointer+ "->" + endPointer);
        System.out.println(new String(arr,0, (int) file.length()));
        file.close();
    }


}
